package com.happly.happlycloud.controller.backend;

import com.happly.happlycloud.common.ServerResponse;
import com.happly.happlycloud.service.ICategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/manage/category")
@Api("商品类别")
public class CategoryManageController {

    @Autowired
    private ICategoryService iCategoryService;

    @RequestMapping("add_category.do")
    @ApiOperation("添加")
    public ServerResponse addCategory(String categoryName, @RequestParam(value = "parentId",defaultValue = "0") int parentId){
        //增加我们处理分类的逻辑
        //权限判断在拦截器里执行
        return iCategoryService.addCategory(categoryName,parentId);
    }

    @RequestMapping("set_category_name.do")
    @ApiOperation("添加")
    public ServerResponse setCategoryName(Integer categoryId,String categoryName){
        //权限判断在拦截器里执行
        return iCategoryService.updateCategoryName(categoryId,categoryName);
    }

    @RequestMapping("get_category.do")
    @ApiOperation("添加")
    public ServerResponse getChildrenParallelCategory(@RequestParam(value = "categoryId" ,defaultValue = "0") Integer categoryId){
        //权限判断在拦截器里执行
        return iCategoryService.getChildrenParallelCategory(categoryId);
    }

    @RequestMapping("get_deep_category.do")
    @ApiOperation("添加")
    public ServerResponse getCategoryAndDeepChildrenCategory(@RequestParam(value = "categoryId" ,defaultValue = "0") Integer categoryId){
        //查询当前节点的id和递归子节点的id
        //0->10000->100000
        //权限判断在拦截器里执行
        return iCategoryService.selectCategoryAndChildrenById(categoryId);
    }

}
